﻿/* 
 * Since 2008 - 2012
 */

package com.hh.bss.project.dao.impl;

import java.util.*;

import com.hh.bss.base.*;
import com.hh.bss.common.MapObjectRowMapper;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.project.dao.*;
import com.hh.bss.project.entity.*;
import com.hh.bss.project.service.*;
import com.hh.bss.project.vo.query.*;
import com.hh.bss.util.*;





import static com.hh.bss.util.ObjectUtils.*;

import org.springframework.stereotype.Repository;

@Repository
public class AccountInvoiceDaoImpl extends BaseHibernateDao<AccountInvoice,java.lang.Integer>  implements AccountInvoiceDao<AccountInvoice,java.lang.Integer>{

	public Class getEntityClass() {
		return AccountInvoice.class;
	}
	
	public Page findPage(AccountInvoiceQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
        
		
		    Class[] os={AccountInvoiceQuery.class};
    		Class property= org.springframework.beans.BeanUtils.findPropertyType(query.getField_type(), os);
        if (property!=null){
        	 if ("java.lang.String".equals(property.getName())){
	    			
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(),query.getQuery());
	    			
	    		}
	    		else if ("java.lang.Integer".equals(property.getName())){
	    			
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), StringHelper.parseInteger(query.getQuery(), 0));
	    			
	    		}
	    		else if ("java.lang.Double".equals(property.getName())){
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), StringHelper.parseDouble(query.getQuery(), 0));
	    		}
	    		else if ("java.util.Date".equals(property.getName())){
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), DateHelper.toDate(query.getQuery(), DateHelper.DEFAULT_DATE_FORMAT));
	    		}
        }	 
        StringBuffer sql2 = new StringBuffer();
        List values = new ArrayList();
        sql2.append("select * from ( ");
        sql2.append(" select a.id,a.pn_nbr pnNbr,a.nbr,a.amount,a.currency,a.status,a.send_dt sendDt,a.sender,a.reciever,b.cv_name recieverName,a.express_id expressId,a.recieve_dt recieveDt,a.comment,a.creator,a.create_dt createDt,a.modifier,a.modified_dt modifiedDt from account_invoice a ");
        sql2.append(" left join cv b on b.id=a.reciever ");
        sql2.append(" ) t where 1=1 ");
        
        if(isNotEmpty(query.getPnNbr())) {
            sql2.append(" and  t.pnNbr like ? ");
            values.add("%"+query.getPnNbr()+"%");
        }
        sql2.append(" order by createDt DESC"); //按创建时间排序
        //System.out.println("============"+sql2+"==============");
        
        return super.getJdbcDao().createPage(sql2.toString(),values.toArray(), new MapObjectRowMapper(), query.getPageSize(), query.getPageNumber());
	}
	

}
